<template>
    <div class="hello">
        <div class="printDv">
            <button class="printQr" @click="putQr">打印机测试</button>
        </div>
    </div>
</template>

<script>
export default {
    name: 'hello',
    data() {
        return {
            msg: 'begin',
            device: null,
            BAdapter: null,
            BluetoothAdapter: null,
            uuid: null,
            main: null,
            bluetoothSocket: null
        }
    },
    methods: {


        putQr: function() {
            let qr_code = 'AA0101A000390001';

            // let url = "http://192.168.3.62:6101/pstprnt";
            let url = "http://192.168.199.204:6101/pstprnt";
            let zpl = '^XA'
            zpl += '^PW384'
            zpl += '^MD10'
            zpl += '^LH0,30'
            zpl += '^FO30,0^BY2.0,2.0^BCN,120,Y,N,N,A^FD' + qr_code + '^FS'
            zpl += '^SEE:GB.DAT'
            zpl += '^CW1,E:MSUNG24.FNT'
            zpl += '^CI26'
            zpl += '^FO8,65^A1N,35,35^FD' + '中华人民共和国' + '^FS'
            zpl += '^PQ1,0,1,Y'
            zpl += '^XZ'

            // let zpm3 = this.pzpl();
            // let formateZpl = this.formateZpl();

            let request = new XMLHttpRequest();
            request.onload = function(e) {
                var arraybuffer = xhr.response;
                // let status = request.status;
                // let data = request.responseText;
            }
            request.open("GET", url, true);
request.responseType = "arraybuffer";
// request.overrideMimeType("text/plain; charset=x-user-defined");
            // request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
            // let _data = new ArrayBuffer(zpl.length)
            // for (var index = 0; index < zpl.length; index++) {
            //     _data[index] = zpl.charCodeAt(index)

            // }
            // request.overrideMimeType()
            request.send(zpl);
            alert('完成')
        },
        putQrcopy: function() {
            let qr_code = 'AA0101A000390001';

            let url = "http://192.168.3.62:6101/pstprnt";
            let zpl = '^XA'
            zpl += '^PW384'
            zpl += '^MD10'
            zpl += '^LH0,30'
            zpl += '^FO30,0^BY2.0,2.0^BCN,120,Y,N,N,A^FD' + qr_code + '^FS'
            zpl += '^SEE:GB.DAT'
            zpl += '^CW1,E:MSUNG24.FNT'
            zpl += '^CI26'
            zpl += '^FO8,65^A1N,35,35^FD' + '中华人民共和国' + '^FS'
            zpl += '^PQ1,0,1,Y'
            zpl += '^XZ'

            let zpm3 = this.pzpl();
            let formateZpl = this.formateZpl();

            let request = new XMLHttpRequest();
            request.onload = function() {
                let status = request.status;
                console.log(status)
                let data = request.responseText;
            }
            request.open("POST", url, true);

            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
            let _data = new ArrayBuffer(zpl.length)
            for (var index = 0; index < zpl.length; index++) {
                _data[index] = zpl.charCodeAt(index)

            }
            request.overrideMimeType()
            request.send(_data);
        },
        pzpl: function() {

            /* switch (Integer.parseInt(discMethod)) {
                case 1:
                    BigDecimal discvalue= new BigDecimal(discValue);
                    BigDecimal dividor= new BigDecimal("10");
                    BigDecimal x= new BigDecimal("10");
                    discvalue = discvalue.divide(dividor);
                    discvalue = x.subtract(discvalue);
        
        
                    zpl2 = "^AV,40,40^FO2,21^FD" + discvalue + "^FS"
                        + "^A@N,40,40,E:HANS.TTF^FO85,46^FD折^FS"
                        + "^A@N,20,20,E:HANS.TTF^FO125,66^FD  折坎价:^FS"
                        + "^AV40,40^FT360,81,1^FD" + newprice + "^FS"
                        + "^A@N,20,20,E:HANS.TTF^FO360,66^FD元 ^FS";//原字体大尝20
        
                    break;
                case 2:
                    zpl2 = "^A@N,20,20,E:HANS.TTF^FO50,20^FD一坣价    " + "折坎价:" + newprice + "元 ^FS";
                    break;
                case 3:
                    zpl2 = "^A@N,35,35,E:HANS.TTF^FO50,50^FD立凝 " + 50 + "元   折坎价:" + newprice + "元^FS";
                    break;
            } */
            //zpl3="^FO1,104^BY1.5,1,40^BCN,,N,N^FD"+newbarcode+"^FS^FO1,146^AON15,15^FD"+newbarcode+"^FS";
            //zpl3="^FO1,104^BY1,1.2,40^BCN,,N,N^FD"+newbarcode+"^FS^FO1,146^AON15,15^FD"+newbarcode+"^FS";
            //zpl3="^FO1,94^BY1,1,50^BCN,,N,N^FD"+newbarcode+"^FS^FO1,146^AON15,15^FD"+newbarcode+"^FS";
            var zpl1 = "^XA^CI26^PW384^A@N,18,18,E:HANS.TTF^FO50,15^FD" + 'aaaaaaaaa1111' + "^FS";
            var zpl2 = "^A@N,35,35,E:HANS.TTF^FO50,50^FD立凝 " + 50 + "元   折坎价:" + 24 + "元^FS";
            var zpl3 = "^FO3,84^BY2,2,50^BCN,50,Y,N,,A^FD" + 'aaaaaaaaa1111' + "^FS";
            var zpl4 = "^A@N,15,15,E:HANS.TTF^FO2,165^FD地址：" + '上大路' + "^FS";
            var zpl5 = "^A@N,15,15,E:HANS.TTF^FO2,180^FD电话：" + '13105198929' + "^FS"
                + "^A@N,15,15,E:HANS.TTF^FT380,192,1^FD价格监督举报电话：12358^FS^XZ";
            var ZPL = zpl1 + zpl2 + zpl3 + zpl4 + zpl5;

            return ZPL;
        },
        formateZpl: function() {
            var zpl = '^XA';
            zpl += '^ DFE:AUTOEXEC.ZPL ^ FS';
            zpl += '^ CWQ, E:HANSSC.TTF'
            zpl += '^ CFQ'
            zpl += '^ XZ'
            return zpl;
        }
    },
    created: function() {


    }
}
</script>
<style lang="css" scoped >
.printQr {
  width: 70%;
  margin-left: 15%;
  height: 100px;
  font-size: 20px;
  font-weight: 500;
  border-radius: 10px;
  box-shadow: 5px 5px 1px #cdcdcd;
  background-color: #8ca5c6;
}
.printDv {
  margin-top: 200px;
  width: 100%;
  height: 100%;
}
</style>

